package com.dyz.leetcode._19_greedy;

import java.util.ArrayDeque;
import java.util.Deque;

public class _1047_removeDuplicates {
    public String removeDuplicates(String s) {
        Deque<Character> deque = new ArrayDeque<>();
        for (char c:s.toCharArray()){
            if(!deque.isEmpty() && deque.peek()==c){
                deque.pop();
            }else {
                deque.push(c);
            }
        }
        StringBuilder sb = new StringBuilder();
        while (!deque.isEmpty()){
            sb.append(deque.pollLast());
        }
        return sb.toString();
    }
}
